<template>
	<view>
		<view class="activity" v-for="item in jsonData" @click="goDetail(item)">
			<image class="one" :src="item.thumb" mode="widthFix"></image>
			<h2>
				{{item.title}} <span>更多 》</span>
			</h2>
			<p v-if="item.active_time">活动时间：{{item.active_time}}</p>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				jsonData: [],
				allpage: 0,
				page: 1,
				limit: 5,
			}
		},
		onLoad() {
			this.getIndex();
		},
		onReachBottom() {
			var _this = this;
			console.log(this.allpage);
			if (this.allpage > this.jsonData.length) {
				_this.getIndex();
			} else {
				_this.ending = true;
			}
		},
		methods: {
			//获取数据
			getIndex() {
				uni.showLoading({
					title: "获取中…"
				})
				uni.$u.http.post("/news/index", {
					class_id: 2,
					limit: this.limit,
					page: this.page
				}).then((res) => {
					if (res.code == 200) {
						this.allpage = res.data.total;
						if (this.page == 1) {
							this.jsonData = res.data.data;
							this.page++;
						} else {
							this.jsonData = this.jsonData.concat(res.data.data);
							if (res.data.data.length >= 1) {
								this.page++;
							}
						}
					}
					uni.hideLoading();
				})
			},

			goDetail(ele) {
				if (ele.urls) {
					// #ifdef MP-WEIXIN
					//const wx = uni.$mp.weixin;
					wx.openOfficialAccountArticle({
						url: ele.urls, // 此处填写公众号文章连接
						success: res => {},
						fail: res => {}
					})
					// #endif
					// #ifdef H5
					window.open(ele.urls, '_blank');
					// #endif

				} else {
					uni.navigateTo({
						url: "/pages/index/news_det?id=" + ele.id
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.activity {
		padding: 40rpx 30rpx 0 30rpx;

		&:last-child {
			padding: 40rpx 30rpx 120rpx 30rpx !important;
		}

		.one {
			width: 100%;
			border-radius: 16rpx;
			//box-shadow:-1px 0 24rpx rgba(0,0,0,.1), 1px 0 24rpx rgba(0,0,0,.1), 0 -1px 24rpx rgba(0,0,0,.1), 0 1px 24rpx rgba(0,0,0,.1);
		}

		h2 {
			position: relative;
			font-weight: normal;
			font-size: 28rpx;
			line-height: 48rpx;
			height: 48rpx;
			padding-right: 120rpx;
			display: -webkit-box;
			overflow: hidden;
			-webkit-line-clamp: 1;
			-webkit-box-orient: vertical;
			margin-top: 12rpx;
			margin-bottom: 12rpx;

			span {
				display: block;
				position: absolute;
				right: 0;
				font-size: 20rpx;
				top: 0rpx;
				line-height: 48rpx;
				color: #999;
			}
		}

		p {
			color: #999;
			font-size: 24rpx;
			padding-bottom: 40rpx;
			border-bottom: 2rpx solid #ccc;
		}
	}

	.activity:last-child p {
		border-bottom: none;
	}
</style>